﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RRRSRoguelike.Managers;
using RRRSRoguelike.Helpers;
using RRRSRoguelike.Helpers.Visualizer;
using System.Drawing;

namespace RRRSRoguelike.Screens
{
    class ReplayScreen:Screen
    {
        bool YesNo;

        public ReplayScreen()
        {
            Panels.Add( new Panel(new Point(4, 3),
                    Visualizer.GetScreenWidth() - 9, Visualizer.GetScreenHeight() - 6));  
        }

        /// <summary>
        /// Calls Show and returns true on Yes and false on No.  Oh! That rhymes. neat.
        /// </summary>
        /// <returns></returns>
        public bool ShowYesNo()
        {
            YesNo = false;
            
            Show();

            return YesNo;
        }

        public override void Show()
        {
            Clear();



            foreach (Panel p in Panels)
            {
                p.Clear();
                p.Draw();
            }

            //prompt user
            Panels[0].Write("Replay? y or n");

            bool replay;
            ConsoleKey answer;
            
            //read keyboard
            answer = Console.ReadKey(true).Key;

            //is y pressed?
            replay = answer == ConsoleKey.Y;

            //if y is pressed start game
            if (replay)
            {
                YesNo = true;
                Panels[0].Write("Replay game " + DungeonManager.Instance.Seed.ToString() + "? y or n");
                if (Console.ReadKey(true).Key == ConsoleKey.Y)
                    GameManager.Instance.DungeonScreen.Show(DungeonManager.Instance.Seed);
                else
                {
                    //Bug fix here.
                    GameManager.Instance.DungeonScreen.Show();
                }

            }
            else if (answer != ConsoleKey.N)
            {
                //only n can quit, no accidental quit.
                Show();
            }
            else
            {
                //Do nothing and fall out of this to the next stage.  Should be the credits screen.
            }
            
            GameManager.Instance.SoundManager.PlaySound(SoundList.Pluck.ToString());
            Clear();
        }
    }
}
